import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/assets_tool/images.dart';
import 'package:tiktokadult/config/config.dart';
import 'package:tiktokadult/hj_page/darkweb/widget/shrink_wrap.dart';
import 'package:tiktokadult/hj_page/home_business/search_page/widget/search_histoty_view.dart';
import 'package:tiktokadult/hj_utils/api_service/acg_service.dart';
import 'package:tiktokadult/hj_utils/api_service/search_service.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';

import '../../../../assets_tool/app_colors.dart';

enum SearchHotTagType {
  video,
  cartton;
}

class SearchHotTagView extends StatefulWidget {
  final SearchHotTagType type;
  final Function(String keyword) onTagClick;

  const SearchHotTagView({super.key, this.type = SearchHotTagType.video, required this.onTagClick});

  @override
  State<SearchHotTagView> createState() => _SearchHotTagViewState();
}

class _SearchHotTagViewState extends State<SearchHotTagView> {
  List<String> get tags => Config.hotSearchTerms;

  bool _isLoading = false;

  @override
  void initState() {
    super.initState();
  }

  void _loadData() async {}

  @override
  Widget build(BuildContext context) {
    if (tags.isEmpty) return SizedBox.shrink();
    return Container(
      padding: EdgeInsets.only(left: 12, right: 12, top: 18),
      width: double.infinity,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Text(
                '大家都在搜',
                style: TextStyle(
                  color: Color(0xE5FFFFFF),
                  fontSize: 18,
                  fontWeight: FontWeight.w600,
                ),
              ),
              Spacer(),
              // InkWell(
              //   onTap: () {},
              //   child: Container(
              //     width: 18,
              //     height: 18,
              //     alignment: Alignment.center,
              //     margin: EdgeInsets.only(left: 8),
              //     child: _isLoading
              //         ? CupertinoActivityIndicator(
              //             color: AppColors.actionRed,
              //             radius: 10,
              //           )
              //         : Image.asset("flash_circle.webp".homePath, width: 18),
              //   ),
              // ),
            ],
          ),
          12.h.sizeBoxH,
          GridView.builder(
            padding: EdgeInsets.zero,
            itemCount: tags.length,
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 4,
              childAspectRatio: 79 / 34,
              mainAxisSpacing: 12,
              crossAxisSpacing: 12,
            ),
            itemBuilder: (context, index) {
              final tag = tags[index];
              return GestureDetector(
                onTap: () {
                  widget.onTagClick(tag);
                  searchHistortyProvider.saveHistories(tag);
                },
                child: Container(
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    color: Color(0x0DFFFFFF),
                    borderRadius: BorderRadius.circular(3),
                  ),
                  child: Text(
                    tag,
                    maxLines: 1,
                    style: TextStyle(
                      color: Color(0xE5FFFFFF),
                      fontSize: 12,
                    ),
                  ),
                ),
              );
            },
          ),
        ],
      ),
    );
  }
}
